package iedcyt.acute.controller.listeners.authorMerge;

import iedcyt.acute.model.AuthorFilterCode;
import iedcyt.acute.model.AuthorMergeModel;
import iedcyt.acute.view.AuthorMergeView;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

/**
 * Controlador para el filtrado de autores
 * @author 53385255R
 *
 */
public class ComboFilterSelection extends SelectionAdapter {

	private AuthorMergeModel _model;
	private AuthorMergeView _view;
	
	/**
	 * @param view
	 * @param model
	 */
	public ComboFilterSelection(AuthorMergeView view, AuthorMergeModel model) {
		this._model = model;
		this._view = view;
	}
	
	/**
	 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
	 */
	public void widgetSelected(SelectionEvent e) {

		Integer filter = _view.getFilterCodeSelected();
		_model.setFilterCode(filter);
		
		updateView();
	}
	
	private void updateView() {
		
		_view.loadAuthors(_model.getAuthors());
		_view.loadCandidateAuthors(_model.getCandidates());
		_view.loadAuthorDocuments(_model.getAuthorDocs());
		_view.loadCandidateDocuments(_model.getCandidateDocs());
		_view.loadAuthorCenters(_model.getAuthorCenters(), _model.isAuthorCentersWarning());
		_view.loadCandidateCenters(_model.getCandidateCenters(),_model.isCandidatCentersWarning());
		_view.loadAuthorCorps(_model.getAuthorCorps(), _model.isAuthorCorpsWarning());
		_view.loadCandidateCorps(_model.getCandidateCorps(), _model.isCandidateCorpsWarning());
		_view.loadAuthorSigns(_model.getAuthorSigns());
		_view.loadCandidateSigns(_model.getCandidateSigns());
		_view.loadAuthorSignsCollaborators(_model.getAuthorCollSigns());
		_view.loadCandidateSignsCollaborators(_model.getCandidateCollSigns());
		_view.loadAuthorAuthorsCollaborators(_model.getAuthorCollAuthors());
		_view.loadCandidateAuthorsCollaborators(_model.getCandidateCollAuthors());
		_view.setSearchText(_model.getSearch());
		
		int code = _model.getFilterCode();
		
		switch (code) {
			case AuthorFilterCode.FILTER_ALL_AUTHORS:
			case AuthorFilterCode.FILTER_AUTHORS_WITH_CANDIDATES:
			case AuthorFilterCode.FILTER_AUTHORS_FOR_REVIEW:
				_view.enabledNextPrev(true);
				break;
			default:
				_view.enabledNextPrev(false);
				break;
			
		}
		
		_view.compareTables();
		

		
	}
}
